package cn.xspace.chatui.bean;

import com.xspace.android.xafcommon.been.BaseEntity;
import com.xspace.android.xafcommon.util.LogUtil;

import java.util.ArrayList;
import java.util.List;

import cn.xspace.library.util.ContentType;

/**
 * Created by liuchen on 2016/10/14.
 */

public class ChatFileEntity extends BaseEntity {

    /**
     * 消息id
     */
    public String msg_id = "";
    /**
     * 文件名称
     */
    public String file_name = "";
    /**
     * 文件本地路径
     */
    public String file_url_local = "";
    /**
     * 文件服务器路径
     */
    public String file_url_remote = "";
    /**
     * 文件大小
     */
    public String file_size = "";
    /**
     * 文件下载状态
     */
    public int file_download_status = DownloadStatus.DOWNLOAD_NOT.toNumber();
    /**
     * 文件类型 1 图片 2语音  4视频  5.位置  7.文件
     */
    public int file_type = ContentType.PICTURE.toNumber();
    /**
     * 经度
     */
    public String lng = "";
    /**
     * 纬度
     */
    public String lat = "";
    /**
     * 语音时长
     */
    public int msg_dutime = 0;
    /**
     * 地址描述
     */
    public String address_desc = "";

    public int isMediaPlayed = 0;
    /**
     * 附件类型 list
     */
    private static List<Integer> fileList = new ArrayList<>();

    static {
        fileList.add(ContentType.PICTURE.toNumber());
        fileList.add(ContentType.VOICE.toNumber());
        fileList.add(ContentType.VEDIO.toNumber());
        fileList.add(ContentType.LOCATION.toNumber());
        fileList.add(ContentType.FILE.toNumber());
    }

    @Override
    public String toString() {
        return "ChatFileEntity{" +
                "msg_id='" + msg_id + '\'' +
                ", file_name='" + file_name + '\'' +
                ", file_url_local='" + file_url_local + '\'' +
                ", file_url_remote='" + file_url_remote + '\'' +
                ", file_size='" + file_size + '\'' +
                ", file_download_status='" + file_download_status + '\'' +
                ", file_type='" + file_type + '\'' +
                ", lng='" + lng + '\'' +
                ", lat='" + lat + '\'' +
                ", msg_dutime='" + msg_dutime + '\'' +
                ", address_desc='" + address_desc + '\'' +
                ", isMediaPlayed='" + isMediaPlayed + '\'' +
                '}';
    }

    public enum DownloadStatus {
        DOWNLOAD_COMPLETE(1),
        DOWNLOAD_ING(2),
        DOWNLOAD_NOT(0),
        DOWNLOAD_FIALED(3);
        private int INum = 0;

        /* 构造器，记住喇，必须是私有的~ */
        private DownloadStatus(int iNum) {
            this.INum = iNum;
        }

        /* 用这个方法代替ordinal()方法，安全，专业，包退包换~ */
        public int toNumber() {
            return this.INum;
        }
    }

    private static final String TAG = "ChatFileEntity";

    /**
     * 判断是否需要存入聊天记录的附件表
     *
     * @return
     */
    public static boolean isNeedSaveFile(int srcType) {
        if (fileList.contains(srcType)) {
            LogUtil.d(TAG, "isNeedSaveFile" + "true");
            return true;
        } else {
            return false;
        }
    }

    /**
     * 通过ContentType 设置显示的文本
     *
     * @param content
     * @param msg_type
     * @return
     */
    public static String getContentByType(String content, int msg_type) {
        if (isNeedSaveFile(msg_type)) {
            if (msg_type == ContentType.LOCATION.toNumber()) {
                return ContentType.LOCATION.getTxt();
                //位置
            } else if (msg_type == ContentType.PICTURE.toNumber()) {
                return ContentType.PICTURE.getTxt();
            } else if (msg_type == ContentType.VEDIO.toNumber()) {
                return ContentType.VEDIO.getTxt();
            } else if (msg_type == ContentType.VOICE.toNumber()) {
                return ContentType.VOICE.getTxt();
            } else if (msg_type == ContentType.FILE.toNumber()) {
                return ContentType.FILE.getTxt();
            }
        } else if (msg_type == ContentType.SYSTEM_WARN.toNumber()) {
            return ContentType.SYSTEM_WARN.getTxt();
        } else if (msg_type == ContentType.OTHER.toNumber()) {
            return ContentType.OTHER.getTxt();
        }
        return content;
    }


    /**
     * @param content
     * @param msg_type
     * @param senderName
     * @return
     */
    public static String getContentByType(String content, int msg_type, String senderName) {
        if (isNeedSaveFile(msg_type)) {
            if (msg_type == ContentType.LOCATION.toNumber()) {
                return ContentType.LOCATION.getTxt();
                //位置
            } else if (msg_type == ContentType.PICTURE.toNumber()) {
                return ContentType.PICTURE.getTxt();
            } else if (msg_type == ContentType.VEDIO.toNumber()) {
                return ContentType.VEDIO.getTxt();
            } else if (msg_type == ContentType.VOICE.toNumber()) {
                return ContentType.VOICE.getTxt();
            } else if (msg_type == ContentType.FILE.toNumber()) {
                return ContentType.FILE.getTxt();
            }
        } else if (msg_type == ContentType.SYSTEM_WARN.toNumber()) {
            return ContentType.SYSTEM_WARN.getTxt();
        } else if (msg_type == ContentType.OTHER.toNumber()) {
            return ContentType.OTHER.getTxt();
        }
        return senderName + "：" + content;
    }
}
